package net.tngou.crawler.quartz;

import java.util.Date;
import java.util.List;

import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import net.tngou.crawler.enums.StateEnum;
import net.tngou.crawler.jdbc.DBManager;
import net.tngou.crawler.jdbc.OrderType;
import net.tngou.crawler.pojo.Crawlerurl;
import net.tngou.crawler.pojo.POJO;
import net.tngou.crawler.pojo.Web;
import net.tngou.crawler.runnable.BaseThread;
import net.tngou.crawler.runnable.CrawlerurlThread;
import net.tngou.crawler.runnable.MyPoolableObjectFactory;
import net.tngou.crawler.service.CrawlerService;


public class CrawlerUrlJob implements Job {
	private static Logger _log = LoggerFactory.getLogger(CrawlerUrlJob.class);
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		if(context!=null)
		_log.info("执行作业： "+context.getJobDetail().getKey() +"  执行时间："+new Date()+"********************************");
		
		CrawlerService service = new CrawlerService();
		
		List<Crawlerurl> list = (List<Crawlerurl>) new Crawlerurl().list("state="+StateEnum.新生成.ordinal(), 1, 100,"id",OrderType.ASC);

		list.forEach(e->{
//			service.saveCravlerUrl(e);
		
		
      
			BaseThread thread = new CrawlerurlThread();
			thread.setData(e);
			thread.start();
		});
		
		// 药店 网站
//		List<Onlinepharmacy> ls=(List<Onlinepharmacy>) service.getList("isuse=1","id", OrderType.ASC, Onlinepharmacy.class);
//		ls.forEach(e->{
//			Crawlerurl crawlerurl = new Crawlerurl();
//			crawlerurl.setWeb(e.getId());
//			crawlerurl.setUrl(e.getUrl());
//			service.saveCravlerUrl(crawlerurl);
//		});
		DBManager.closeConnection();
	

	}
	public static void main(String[] args) throws JobExecutionException {
		while (true) {
			new CrawlerUrlJob().execute(null);
			
		}
		
	}
}

